package com.ruoyi.dataBase.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.dev33.satoken.annotation.SaMode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dataBase.domain.vo.IndustrialFunctDeptVo;
import com.ruoyi.dataBase.domain.bo.IndustrialFunctDeptBo;
import com.ruoyi.dataBase.service.IIndustrialFunctDeptService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职能部门
 *
 * @author yangzhen
 * @date 2025-11-07
 */
@Tag(name = "职能部门", description = "职能部门相关接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dataBase/functDept")
public class IndustrialFunctDeptController extends BaseController {

    private final IIndustrialFunctDeptService iIndustrialFunctDeptService;

    /**
     * 查询职能部门列表
     */
    @Operation(
        summary = "职能部门列表",
        description = "用于查询职能部门"
    )
    @SaCheckPermission("dataBase:functDept:list")
    @GetMapping("/list")
    public TableDataInfo<IndustrialFunctDeptVo> list(IndustrialFunctDeptBo bo, PageQuery pageQuery) {
        return iIndustrialFunctDeptService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出职能部门列表
     */
    @Operation(
        summary = "导出职能部门列表",
        description = "用于导出职能部门列表"
    )
    @SaCheckPermission("dataBase:functDept:export")
    @Log(title = "职能部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IndustrialFunctDeptBo bo, HttpServletResponse response) {
        List<IndustrialFunctDeptVo> list = iIndustrialFunctDeptService.queryList(bo);
        ExcelUtil.exportExcel(list, "职能部门", IndustrialFunctDeptVo.class, response);
    }

    /**
     * 获取职能部门详细信息
     *
     * @param id 主键
     */
    @Operation(
        summary = "职能部门详细信息",
        description = "用于获取职能部门详细信息"
    )
    @SaCheckPermission("dataBase:functDept:query")
    @GetMapping("/{id}")
    public R<IndustrialFunctDeptVo> getInfo(@NotNull(message = "主键不能为空")
                                            @PathVariable String id) {
        return R.ok(iIndustrialFunctDeptService.queryById(id));
    }

    /**
     * 新增职能部门
     */
    @Operation(
        summary = "新增职能部门",
        description = "用于新增职能部门"
    )
    @SaCheckPermission("dataBase:functDept:add")
    @Log(title = "职能部门", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IndustrialFunctDeptBo bo) {
        return toAjax(iIndustrialFunctDeptService.insertByBo(bo));
    }

    /**
     * 修改职能部门
     */
    @Operation(
        summary = "修改职能部门",
        description = "用于修改职能部门"
    )
    @SaCheckPermission(value = {"dataBase:functDept:edit", "dataBase:functDept:review"}, mode = SaMode.OR)
    @Log(title = "职能部门", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IndustrialFunctDeptBo bo) {
        return toAjax(iIndustrialFunctDeptService.updateByBo(bo));
    }

    /**
     * 删除职能部门
     *
     * @param ids 主键串
     */
    @Operation(
        summary = "删除职能部门",
        description = "用于删除职能部门"
    )
    @SaCheckPermission("dataBase:functDept:remove")
    @Log(title = "职能部门", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iIndustrialFunctDeptService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
